---
# Variable configuration.
- include_tasks: variables.yml

# Setup/install tasks.
- include_tasks: setup-RedHat.yml
  when: ansible_os_family == 'RedHat'

- include_tasks: setup-Debian.yml
  when: ansible_os_family == 'Debian'

- include_tasks: initialize.yml
- include_tasks: configure.yml

# Otherwise users and db are created in default data dir location (Ubunut: /var/lib/postgresql/...)
# instead of the custom `postgresql_data_dir`
- name: Reset Ansible handlers to ensure users and db are created in data dir {{ postgresql_data_dir }}
  meta: flush_handlers

- name: Ensure PostgreSQL is started and enabled on boot.
  service:
    name: "{{ postgresql_daemon }}"
    state: "{{ postgresql_service_state }}"
    enabled: "{{ postgresql_service_enabled }}"

# Configure PostgreSQL.
- import_tasks: users.yml
- import_tasks: databases.yml
- import_tasks: users_props.yml
